//
//  ZYHomeTitleView.swift
//  weibo007
//
//  Created by 陈宗毅 on 15/12/20.
//  Copyright © 2015年 czy. All rights reserved.
//

import UIKit

class ZYHomeTitleView: UIButton {

    init(imageName:String,title:String){
        
        super.init(frame: CGRectZero)
        
        setImage(UIImage(named:imageName), forState: UIControlState.Normal)
        setTitle(title, forState: UIControlState.Normal)
        setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)
        sizeToFit()
        
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    
    
  //修改图片和文字的布局
    override func layoutSubviews() {
        super.layoutSubviews()
        //文字的origin.x 设置为0
        //! 和？都行的情况下  建议加?
        self.titleLabel?.frame.origin.x = 0
        
        //将图片的origin.x设置为文字的宽度
        //self.titleLabel ？frame.width, 可能有值或者没有值,返回可选类型
        
        //self.imageView?.frame.origin.x 是CGFloat类型，不接受nil
        self.imageView?.frame.origin.x = self.titleLabel!.frame.width + 3
        
    }

}
